package jia.core.flags;

// ====================================================
/**
 * Parent object for state flags. To create a new flag object, extend this
 * object and define some constants for your flag names:
 * <p/>
 * public static final int IS_NIFTY = 1; public static final int IS_KEEN = 2;
 * <p/>
 * When creating your flag constants, remember that they are bitwise-OR'd
 * together, so keep them in powers of two. 1, 2, 4, 8, 16, 32, 64, ..., etc.
 *
 * @author Alec Lanter
 */
public abstract class Flags{
	protected static final int UNSET_MASK = 0xFFFFFFFF;
	protected int flags = 0;

	// ===============================================
	/**
	 */
	public Flags(){
		// GNDN
	}

	// ===============================================
	/**
	 * @param startVal
	 */
	public Flags(int startVal){
		flags = startVal;
	}

	// ===============================================
	/**
	 * @return
	 */
	public int getIntVal(){
		return flags;
	}

	// ====================================================
	/**
	 * @param flag
	 *
	 * @return
	 */
	public boolean hasFlag(int flag){
		return (flags & flag) != 0;
	}

	// ====================================================
	/**
	 * @param flag
	 */
	public void setFlag(int flag){
		flags |= flag;
	}

	// ====================================================
	/**
	 * @param flag
	 */
	public void clearFlag(int flag){
		flags &= (flag ^ UNSET_MASK);
	}

	// ====================================================
	/**
	 * @param flag
	 */
	public void toggleFlag(int flag){
		flags ^= flag;
	}
}
